"use strict"
//查询接口日志
const mvc = require("cosjs.mvc");
exports.query = async function () {
    const sid = this.get('sid', 'int');
    const uid = this.get('uid', 'string');
    const path = this.get('path', 'string');
    const time = this.get('time', 'string');
    if (!sid) {
        return [];
    }

    let plog_mode = mvc.model.mongo('apiLog', sid);
    let _que = {};
    if (uid) {
        _que['uid'] = uid;
    }
    if (path) {
        _que['path'] = { '$regex': path };
    }

    let tt;
    if (time) {
        tt = time.split(' - ');
    }
    if (tt) {
        let btime = Date.parse(tt[0]);
        let etime = Date.parse(tt[1]);
        _que['$and'] = [{ 'time': { '$gte': btime } }, { 'time': { '$lt': etime } }];
    }
    let $page = this.get('page', 'int') || 1;
    let $size = this.get('size', 'int') || 20;
    let dbsort = { "time": -1 };
    let _ret = await plog_mode.page(_que, $page, $size, dbsort, {});
    return _ret;
}


